<?php
//
//                            _ooOoo_
//                           o8888888o
//                           88" . "88
//                           (| -_- |)
//                           O\  =  /O
//                        ____/`---'\____
//                      .'  \\|     |//  `.
//                     /  \\|||  :  |||//  \
//                    /  _||||| -:- |||||-  \
//                    |   | \\\  -  /// |   |
//                    | \_|  ''\---/''  |   |
//                    \  .-\__  `-`  ___/-. /
//                  ___`. .'  /--.--\  `. . __
//               ."" '<  `.___\_<|>_/___.'  >'"".
//              | | :  `- \`.;`\ _ /`;.`/ - ` : | |
//              \  \ `-.   \_ __\ /__ _/   .-` /  /
//         ======`-.____`-.___\_____/___.-`____.-'======
//                            `=---='
//        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//                      Buddha Bless, No Bug !
namespace dexcedu;

require __DIR__ . '/../vendor/autoload.php';
include_once __DIR__ . '/../model/return.php';


try {
    // 进制预检访问接口
    if (strtolower($_SERVER['REQUEST_METHOD']) == 'options') {
        exit;
    }
    extract(DBFIG);
    $tpl = '%s:host=%s;dbname=%s;port=%s;charset=%s';
    $args = [$type, $host, $dbname, $port, $charset];
    $dsn = sprintf($tpl, ...$args);
    $model = new Model($dsn, $username, $password);
    //秘钥 用作登录修改的
    $secretKey = '93a1c3a4b6e9f0d1e4b0f78a9cd7b0d1a78d9b0e4b0e';
    $myCallback = new Callback();
    $accessKeyId = 'LTAI5tJiVust5rLQNu3biMFb';
    $accessKeySecret = 'EzJbyG3q4h73GOUmMe3x1OurE5ztps';
    $Toquill =   new Toquill($secretKey, $model, $myCallback, $accessKeyId, $accessKeySecret);
    $controller  = new Apicontroller($model, $Toquill);
    $a = $_GET['post'];
    if ($a) {
        echo $controller->$a();
    } else {
        echo json_encode(retur('erro', '非法访问', 3000));
    }
} catch (\Throwable $th) {
    $errorMessage = $th->getMessage();
    $errorLine = $th->getLine();
    json_encode(retur('程序错误', "错误信息：{$errorMessage}，发生在第 {$errorLine} 行。", 3001));
}
